#define _CRT_SECURE_NO_WARNINGS 1
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include<math.h>
#include<stdlib.h>
#include<stdio.h>
using namespace std;

int main()
{
    int row, col, k = 4, d, m = 0, i1, j1, sum = 0, e = 0;
    char a[82] = { 0 }, b[405] = { 0 }, c[25][25] = { 0 };
    memset(b, '0', 400);
    cin>>row>>col;
    getchar();
    gets(a);
    int l = strlen(a);
    for (int i = 0; i < l; i++)
    {
        if (a[i] == ' ')
        {
            k += 5;
            continue;
        }
        else
        {
            m = 0;
            d = a[i] - 'A' + 1;
            while (d != 0)
            {
                b[k - m] = d % 2 + '0';
                d = d / 2;
                m++;
            }
            k += 5;
        }
    }
    i1 = row - 1;
    j1 = col;
    int i = 0, j = 0, temp;
    while (sum != row * col)
    {
        if (e % 4 == 0)
        {
            for (temp = 0; temp < j1; temp++)
            {
                c[i][j + temp] = b[sum];
                sum++;
            }
            j += temp - 1;
            i++;
            j1--;

        }
        else if (e % 4 == 1)
        {
            for (temp = 0; temp < i1; temp++)
            {
                c[i + temp][j] = b[sum];
                sum++;
            }
            i += temp - 1;
            j--;
            i1--;

        }
        else if (e % 4 == 2)
        {
            for (temp = 0; temp < j1; temp++)
            {
                c[i][j - temp] = b[sum];
                sum++;
            }
            j = j - (temp - 1);
            j1--;
            i--;

        }
        else if (e % 4 == 3)
        {
            for (temp = 0; temp < i1; temp++)
            {
                c[i - temp][j] = b[sum];
                sum++;
            }
            i -= temp - 1;
            i1--;
            j++;

        }
        e++;
    }
    for (int i = 0; i < row; i++)
        printf("%s", c[i]);
    return 0;
}